import React from 'react';
import Toast from 'antd-mobile/lib/toast';
import CategoryItem from './CategoryItem';
import { fetchHomeCategoryProductlist } from '../api';
import './index.less';


export default class HomeCategoryProductlist extends React.PureComponent {
  state = {
    allData: [],
    show:[]
  }
  componentDidMount() {
    Toast.loading('数据加载中', 10);
    fetchHomeCategoryProductlist().then(({ data }) => {
      const show = data.map(() => true);
      this.setState({ allData: data.filter(({ category_id }) => +category_id !== 142 && +category_id !== 145), show });
      Toast.hide();
    })
  }

  accordionChange(i) {
    let { show } = this.state;
    show[i] = !this.state.show[i];
    this.setState({ show })
  }

  render() {
    const { allData } = this.state;
    return (
      allData.map((item, index)=>(
        <CategoryItem key={index} CategoryItem={item} isAdd={!(index % 2)}  />
      ))
    );
  }
}